package com.checkoutcheckins.client.panels;

import com.checkoutcheckins.client.data.Utils;
import com.checkoutcheckins.client.data.foursquare.Checkin;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;

public class VenuePanel extends VerticalPanel {

	public VenuePanel(Checkin checkin) {
		super();
		init(checkin, false);
	}

	public VenuePanel(Checkin checkin, Boolean getMayor) {
		super();
		init(checkin, getMayor);
	}

	private void init(Checkin checkin, Boolean getMayor) {
		this.setWidth("100%");
		this.setStyleName("venuePanel");

		FlexTable locationTable = new FlexTable();
		locationTable.setStyleName("locationTable");

		String venueTitle = "";

		if (checkin.getUser() != null) {
			this.add(new HTML("<center><b>" + "<a target='blank'"
					+ " href='http://www.foursquare.com/user/-"
					+ checkin.getUser().getId() + "'>"
					+ checkin.getUser().getFirstname() + " "
					+ checkin.getUser().getLastname() + "</a></b></center>"));
			this.add(new HTML("<center>visited</center>"));
		}

		if (checkin.getVenue().getPrimarycategory() != null) {
			venueTitle = "<img style='float: left' src='"
					+ checkin.getVenue().getPrimarycategory().getIconurl()
					+ "'>";
		}

		venueTitle = venueTitle + "<a target='blank'"
				+ " href='http://www.foursquare.com/venue/"
				+ checkin.getVenue().getId() + "'>"
				+ checkin.getVenue().getName() + "</a>";

		HTML venueName = new HTML(venueTitle);
		venueName.setWidth("100%");
		venueName.addStyleName("center");
		venueName.addStyleName("onetwenty");

		this.add(venueName);

		HTML isAt = new HTML("located at");
		isAt.setWidth("100%");
		isAt.addStyleName("center");
		isAt.addStyleName("seventy");

		this.add(isAt);

		if (checkin.getVenue().getAddress() != null) {
			Utils.addRowToTable(locationTable, checkin.getVenue().getAddress());
		}
		if (checkin.getVenue().getCity() != null) {

			String cityStateZip = checkin.getVenue().getCity() + ", "
					+ checkin.getVenue().getState();

			if (checkin.getVenue().getZip() != null) {
				cityStateZip = " " + checkin.getVenue().getZip();
			}

			Utils.addRowToTable(locationTable, cityStateZip);
		}

		if (checkin.getVenue().getPhone() != null) {
			Utils.addRowToTable(locationTable, checkin.getVenue().getPhone());
		}

		if (checkin.getShout() != null) {
			Utils.addRowToTable(locationTable, "<span style='font-size: 80%"
					+ ";font-weight: bold" + "'>you shouted</span>");
			Utils.addRowToTable(locationTable, checkin.getShout());
		}

		this.add(locationTable);

		// // if (checkin.getVenue().get != "") {
		// // venueTable.setHTML(venueTable.getRowCount(), 0,
		// // "<span style='font-size: 80%'>tweeting with</span>");
		// // venueTable
		// // .setHTML(
		// // venueTable.getRowCount(),
		// // 0,
		// //
		// "<a target='_blank' style='font-weight: bold; color: #33CCFF;' href='http://twitter.com/"
		// // + venue.getVenuetwitter()
		// // + "'>@"
		// // + venue.getVenuetwitter() + "</a>");
		// // }
		//		
		// if (venuephone. != null) {
		//
		// Log.debug("venue mayor id: " + venue.getVenuemayoruserid());
		// Log.debug("Current user id: " + coci.getFsUser().getId());
		//
		// if (venue.getVenuemayoruserid().equals(coci.getFsUser().getId())) {
		// venueTable.setHTML(venueTable.getRowCount(), 0,
		// "<span style='font-size: 150%; font-weight: bold;'>"
		// + "YOU</span> are the Mayor");
		// venueTable
		// .setHTML(
		// venueTable.getRowCount(),
		// 0,
		// "<span style='font-size: 80%'>with</span>"
		// +
		// "<span style='color: #FF3366; font-size: 100%; font-weight: bold;'> "
		// + venue.getVenuemayorcount()
		// + " </span>"
		// + "<span style='font-size: 80%'>checkins</span>");
		//
		// } else {
		//
		// venueTable.setHTML(venueTable.getRowCount(), 0,
		// "<span style='font-size: 80%'>with Mayor</span>");
		// venueTable.setHTML(venueTable.getRowCount(), 0,
		// "<a target='_blank' href='http://www.foursquare.com/user/-"
		// + venue.getVenuemayoruserid() + "'>"
		// + "<img style='border: 1px solid black' src='"
		// + venue.getVenuemayorphoto() + "'><br>"
		// + venue.getVeneuemayorfirstname() + " "
		// + venue.getVenuemayorlastname() + "</a>");
		//
		// venueTable
		// .setHTML(
		// venueTable.getRowCount(),
		// 0,
		// "<span style='font-size: 80%'>who has been here</span>"
		// +
		// "<span style='color: #FF3366; font-size: 100%; font-weight: bold;'> "
		// + venue.getVenuemayorcount()
		// + " </span>"
		// + "<span style='font-size: 80%'>times</span>");
		// }
		// }
		// if (venue.getVenuecheckinnum() != 0) {
		//
		// venueTable
		// .setHTML(
		// venueTable.getRowCount(),
		// 0,
		// "<span style='font-size: 80%'>it has</span>"
		// +
		// "<span style='color: #FF3366; font-size: 110%; font-weight: bold;'> "
		// + venue.getVenuecheckinnum()
		// + " </span>"
		// + "</b><span style='font-size: 80%'> total checkins</span>");
		// }

		if (getMayor) {

		}

	}
}
